﻿using GalaSoft.MvvmLight.Messaging;
using JiveMessenger.Models;
using JiveMessenger.User;
using JiveMessenger.ViewModels;
using System;
using System.Windows;

namespace JiveMessenger.Views
{
    /// <summary>
    /// Description for InviteContactToGroup.
    /// </summary>
    public partial class InviteContactToGroupWindow : Window
    {
        /// <summary>
        /// Initializes a new instance of the InviteContactToGroup class.
        /// </summary>
        public InviteContactToGroupWindow(IChatGroup group,IClient currentClient)
        {
            InitializeComponent();
            switch (group.Type)
            {
                case GroupType.JiveChatGroup:
                    this.DataContext = new ViewModelInviteContactToGroup(currentClient, (JiveChatGroupModel)group);
                    break;
                default:
                    throw new NotImplementedException();
            }

            Messenger.Default.Register<NotificationMessage>(this, msg =>
                {
                    if (msg.Notification == "CloseWindow" && msg.Sender == this.DataContext)
                    {
                        if (msg.Target != null && msg.Target.GetType() == typeof(bool))
                            this.DialogResult = (bool)msg.Target;
                        this.Close();
                    }
                });
        }

        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            ((ViewModelInviteContactToGroup)this.DataContext).Cleanup();
        }
    }
}